﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreFrame.Business;
using MarchEstate.Manager.BusinesEntity;
using CoreFrame.Core.Orm;

namespace MarchEstate.Manager.Dao.Carport
{
    public class CarDao : AbstractDao
    {
        /// <summary>
        /// 是否存在该区域对象
        /// </summary>
        /// <param name="_areaCode"></param>
        /// <returns></returns>
        public bool ExistAreaModel(string _code)
        {
            string strWhere = "Code = '" + _code + "'";
            return BindEntity<AbstractCarArea>.CreateInstanceDAL(oleDb, WorkId).Exists(strWhere);
        }

        public bool AddArea(AbstractCarArea areaInfo)
        {
            int ret = 0;
            ret = BindEntity<AbstractCarArea>.CreateInstanceDAL(oleDb, WorkId).Add(areaInfo);
            return ret>0;
        }

        public bool UpdateArea(AbstractCarArea areaInfo)
        {
            int ret = 0;
            ret = BindEntity<AbstractCarArea>.CreateInstanceDAL(oleDb, WorkId).Update(areaInfo);
            return ret > 0;
        }

        public System.Data.DataTable GetCarAreaList()
        {
            string strsql = @"select * from WY_CarArea";
            return oleDb.GetDataTable(strsql);
        }

        public bool DeleteCarArea(string _code)
        {
            string strWhere = "Code = '" + _code + "'";
            return BindEntity<AbstractCarArea>.CreateInstanceDAL(oleDb, WorkId).Delete(strWhere) > 0;
        }

        public List<AbstractCarport> GetCarportList(string _carAreaCode)
        {
            string strWhere = "";
            if (_carAreaCode != "")
            {
                strWhere = "CarAreaCode = '" + _carAreaCode + "'";
            }
            return BindEntity<AbstractCarport>.CreateInstanceDAL(oleDb, WorkId).GetListArray(strWhere);
        }

        public bool DeleteCarport(string _carPortId)
        {
            string strWhere = "CarPortId = '" + _carPortId + "'";
            return BindEntity<AbstractCarport>.CreateInstanceDAL(oleDb, WorkId).Delete(strWhere) > 0;
        }

        public bool ExistCarportModel(string _code)
        {
            string strWhere = "Code = '" + _code + "'";
            return BindEntity<AbstractCarport>.CreateInstanceDAL(oleDb, WorkId).Exists(strWhere);
        }

        public bool AddCarport(AbstractCarport carportManager)
        {
            int ret = 0;
            ret = BindEntity<AbstractCarport>.CreateInstanceDAL(oleDb, WorkId).Add(carportManager);
            return ret > 0;
        }

        public bool UpdateCarport(AbstractCarport carportManager)
        {
            int ret = 0;
            ret = BindEntity<AbstractCarport>.CreateInstanceDAL(oleDb, WorkId).Update(carportManager);
            return ret > 0; ;
        }

        public bool JoinCarport(string carportId, string ownerId, string ownerName, string roomNumber, string carNumber, string carbrand)
        {
            string strsql = @"update WY_Carport set OwnerId='{1}',OwnerName='{2}',RoomNumber='{3}',CarNumber='{4}',Carbrand='{5}',JoinFlag=1,JoinDate='{6}' where CarPortId='{0}'";
            strsql = string.Format(strsql, carportId, ownerId, ownerName, roomNumber, carNumber, carbrand, DateTime.Now.Date);
            return oleDb.DoCommand(strsql) > 0;
        }

        public bool CancelJoin(string srccId)
        {
            string strsql = @"update WY_Carport set JoinFlag=0 where CarPortId='" + srccId + "'";
            return oleDb.DoCommand(strsql) > 0;
        }
    }
}
